package org.jeecg.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.domain.WorkerCertification;
import org.jeecg.domain.dto.ServeProviderRenZhengDto;
import org.jeecg.service.WorkerCertificationService;
import org.jeecg.mapper.WorkerCertificationMapper;
import org.jeecg.utils.ResponseResult;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author 86182
* @description 针对表【worker_certification(服务人员认证信息表)】的数据库操作Service实现
* @createDate 2024-12-24 14:48:17
*/
@Service
public class WorkerCertificationServiceImpl extends ServiceImpl<WorkerCertificationMapper, WorkerCertification>
    implements WorkerCertificationService{
    //    服务人员认证信息分页
    @Override
    public ResponseResult renzhengList(ServeProviderRenZhengDto serveProviderDto) {
        IPage<WorkerCertification> page = new Page<>(serveProviderDto.getPageNum(), serveProviderDto.getPageSize());
        LambdaQueryWrapper<WorkerCertification> wrapper = Wrappers.<WorkerCertification>lambdaQuery()
                .like(StringUtils.checkValNotNull(serveProviderDto.getName()), WorkerCertification::getName, serveProviderDto.getName())
                .like(StringUtils.checkValNotNull(serveProviderDto.getIdCardNo()), WorkerCertification::getIdCardNo, serveProviderDto.getIdCardNo())
                .eq(StringUtils.checkValNotNull(serveProviderDto.getCertificationStatus()), WorkerCertification::getCertificationStatus, serveProviderDto.getCertificationStatus())
                .eq(StringUtils.checkValNotNull(serveProviderDto.getCheckStatus()), WorkerCertification::getCheckStatus, serveProviderDto.getCheckStatus());
        this.page(page, wrapper);
        return ResponseResult.okResult(page);
    }
    //    认证信息
    @Override
    public ResponseResult renzhengInfo(Long id) {
        WorkerCertification byId = this.getById(id);
        if (byId != null) {
            return ResponseResult.okResult(byId);
        } else {
            return ResponseResult.errorResult(500, "未查询到认证信息");
        }
    }

    //    审核通过
    @Override
    public ResponseResult tongguo(Long id) {
        WorkerCertification byId = this.getById(id);
        if (byId != null) {
          if (byId.getCheckStatus() == 1){
              return ResponseResult.errorResult(200, "已审核,点击无效");
          }else{
              byId.setCheckStatus(1);
              byId.setCertificationStatus(2);
              byId.setReviewTime(new Date());
              boolean b = this.updateById(byId);
              return b?ResponseResult.okResult(200,"审核通过"):ResponseResult.errorResult(500,"审核失败");
          }
        } else {
            return ResponseResult.errorResult(500,"审核失败,该服务人员不存在");
        }
    }

    //    审核驳回
    @Override
    public ResponseResult bohui(Long id) {
        WorkerCertification byId = this.getById(id);
        if (byId != null) {
            if (byId.getCheckStatus() == 1){
                return ResponseResult.errorResult(200, "已审核,点击无效");
            }else{
                byId.setCheckStatus(1);
                byId.setCertificationStatus(3);
                byId.setReviewTime(new Date());
                boolean b = this.updateById(byId);
                return b?ResponseResult.okResult(200,"审核驳回"):ResponseResult.errorResult(500,"审核失败");
            }
        } else {
            return ResponseResult.errorResult(500,"审核失败,该服务人员不存在");
        }
    }
}




